<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">签收编号</label>
                                    <div class="layui-input-inline">
                                        <input name="code" class="layui-input" type="text" placeholder="请输入签收编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">采购编号</label>
                                    <div class="layui-input-inline">
                                        <input name="purchaseCode" class="layui-input" type="text"
                                               placeholder="请输入采购编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="status">
                                            <option value="">请选择状态</option>
                                            <option value="signed">已签收</option>
                                            <option value="inventoryIn">已入库</option>
                                            <option value="inventoryPart">部分入库</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <a class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit
                                       type="button">搜索</a>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="addPurchaseSignOrderBtn" class="layui-btn icon-btn color-green">添加采购订单签收信息
                            </button>
                        </div>
                        <div class="lay-btn-rt">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="purchaseSignTable" lay-filter="purchaseSignTable"></table>
        </div>
    </div>
</div>

<style>
    .addOrderSigningInfo label {
        width: 85px;
        padding: 10px 10px 10px 0px;
    }

    .addOrderSigningInfo .layui-table-cell, .addPurchaseCommodity .layui-table-cell, .purchaseSignDetails .layui-table-cell {
        height: auto;
        max-height: 80px;
    }

    .layui-table-cell img {
        height: auto;
        width: auto;
        max-height: 80px;
    }


    /*div[lay-id="addPurchaseOrderTable"] .layui-form,*/
    /*div[lay-id="addPurchaseOrderTable"] .layui-table-box,*/
    /*div[lay-id="addPurchaseOrderTable"] .layui-table-body*/
    div[lay-id="addPurchaseOrderTable"] .layui-table-cell {
        overflow: visible;
    }

    td[data-field="packName"] dl {
        max-height: 150px;
    }

</style>

<!-- 表格操作列 -->
<script type="text/html" id="purchaseSignTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">查看详情</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="print">打印签收单</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="">签收</a>-->
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="plantLable">打印条码</a>
</script>
<!-- 打印条码表格操作列 -->
<script type="text/html" id="purchaseSignLableTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="printBarcode">打印条码</a>
</script>

<!--addOrderSigningInfo-->
<!-- 添加采购订单签收信息 -->
<script type="text/html" id="addOrderSigningInfo">
    <div class="layui-fluid addOrderSigningInfo">
        <form class="layui-form model-form" lay-filter="addOrderSigningInfoForm"
              style="height: calc(100% - 5px); overflow: hidden">
            <div class="open-details-box" style="height: calc(100% - 75px);">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单分类</label>
                        <div class="layui-input-inline">
                            <input type="text" name="purchaseTypeName" class="layui-input" readonly>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">供应商</label>
                        <div class="layui-input-inline">
                            <input type="text" name="supplier" class="layui-input" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">供货订单</label>
                        <div class="layui-input-inline">
                            <select name="skuCode" lay-verify="required" lay-filter="skuCode"></select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">供应商联系人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="supplierName" class="layui-input" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">采购部门</label>
                        <div class="layui-input-inline">
                            <select name="department" id="department" disabled>
                                <option value="1">采购部</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">采购申请人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="creatorName" class="layui-input" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单审核人</label>
                        <div class="layui-input-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="orderAuditor" class="layui-input" readonly>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <a class="layui-btn" id="addSigningProductBtn">添加签收物料</a>
                </div>
                <!-- 表格 -->
                <div class="layui-form-item">
                    <table class="layui-table" id="addPurchaseOrderTable" lay-filter="addOrderSigningInfoTable"></table>
                </div>
            </div>

            <div class="layui-form-item text-right">
                <a class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</a>
                <a class="layui-btn" lay-filter="addOrderSigningInfoSubmit" lay-submit>提交</a>
            </div>
        </form>


    </div>
</script>

<!--addOrderSigningInfoSelectBar-->
<!--添加采购订单签收信息下拉框-->
<!--<script type="text/html" id="addOrderSigningInfoSelectBar">-->
<!--    -->
<!--&lt;!&ndash;    <select name="packName" id="packName" lay-filter="packName" lay-verify="required"></select>&ndash;&gt;-->
<!--</script>-->
<script type="text/html" class="layui-form" id="addOrderSigningInfoSelectBar">
    <select name="packName" id="packName" lay-filter="packName" lay-verify="required"></select>
</script>


<!--addSigningProduct-->
<!-- 添加采购商品 -->
<script type="text/html" id="addSigningProduct">
    <div class="layui-fluid addPurchaseCommodity">
        <!-- 头部操作栏 -->
        <form class="layui-form model-form" style="height: calc(100% - 5px);overflow: hidden;">
            <div class="open-details-box" style="height: calc(100% - 75px);">
                <!-- 表格 -->
                <div class="table-bor">
                    <table class="layui-table" id="addSigningProductTable" lay-filter="addSigningProductTable"></table>
                </div>
                <div class="layui-form-item">
                    <!-- 表格 -->
                    <table class="layui-table" id="addSigningProductTableList"
                           lay-filter="addSigningProductTableList"></table>
                </div>
            </div>
            <div class="layui-form-item text-right">

                <a class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</a>
                <a class="layui-btn" id="addSigningProductSubmit">提交</a>
            </div>
        </form>
    </div>
</script>

<!--addPurchaseCommodityBar-->
<!-- 添加采购商品操作 -->
<script type="text/html" id="addPurchaseCommodityBar">
    <a class="layui-btn layui-btn-xs" lay-event="addPurchaseCommodityDetails">详情</a>
</script>


<!--purchaseSignDetails-->
<!-- 详情 -->
<script type="text/html" id="purchaseSignDetails">
    <div class="layui-fluid purchaseSignDetails">
        <!-- 头部操作栏 -->
        <form class="layui-form model-form" style="height: calc(100% - 5px);overflow: hidden;">
            <div class="open-details-box" style="height: calc(100% - 75px);">
                <!-- 表格 -->
                <div class="table-bor">
                    <table class="layui-table" id="purchaseSignDetailsTable"
                           lay-filter="purchaseSignDetailsTable"></table>
                </div>
                <div class="layui-form-item">
                    <!-- 表格 -->
                    <table class="layui-table" id="purchaseSignDetailsTableList"
                           lay-filter="purchaseSignDetailsTableList"></table>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            </div>
        </form>
    </div>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload'], function () {
        let $ = layui.jquery;
        let layer = layui.layer;
        let form = layui.form;
        let table = layui.table;
        let config = layui.config;
        let admin = layui.admin;
        let upload = layui.upload;

        form.render('select');

        // 渲染表格
        let insTb = table.render({
            elem: '#purchaseSignTable',
            url: config.base + 'enterprisecab/order/admin/purchaseSign/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'code', sort: true, title: '签收记录编号'}
                , {field: 'purchaseCode', sort: true, title: '采购单编号'}
                , {field: 'supplier', sort: true, title: '供应商'}
                , {field: 'purchaseTypeName', sort: true, title: '签收类型'}
                , {field: 'skuNum', sort: true, title: '签收SKU数'}
                , {field: 'orderMoney', sort: true, title: '签收金额'}
                , {field: 'statusDesc', sort: true, title: '状态'}
                , {field: 'creatorName', sort: true, title: '操作员'}
                , {field: 'createTime', sort: true, title: '入库时间'}
                , {align: 'left', toolbar: '#purchaseSignTableBar', title: '操作', width: 180}
            ]],
            done: function (res, curr, count) {
            }
        });

        // 工具条点击事件
        table.on('tool(purchaseSignTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event === 'details') {
                showPurchaseSignDetails(data);
            } else if (obj.event === 'plantLable') {
                showPlantLable(data);
            }
        });

        //监听排序
        table.on('sort(purchaseTable)', function (obj) {
            table.reload('purchaseTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#addPurchaseSignOrderBtn').click(function () {
            showAddPurchaseOrder();
        });

        //显示详情弹窗
        function showPurchaseSignDetails(data) {
            admin.open({
                type: 1,
                area: ['1400px', '800px'],
                offset: '65px',
                title: '采购签收详情',
                content: $('#purchaseSignDetails').html(),
                success: function () {
                    let purchaseSignDetailsTableData = []
                    admin.reqSync('enterprisecab/order/admin/purchaseSign/getPurchaseSignVOById', {id: data.id}, res => {
                        if (res.code === 200) {
                            purchaseSignDetailsTableData.push(res.data);
                            console.log(res.data)
                        }
                    }, 'GET');

                    let purchaseSignDetailsTb = table.render({
                        elem: '#purchaseSignDetailsTable',
                        data: purchaseSignDetailsTableData,
                        page: false,
                        height: 150,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'code', title: '签收单编号'}
                            , {field: 'purchaseCode', title: '生产/采购订单'}
                            , {field: 'purchaseTypeName', title: '采购类型'}
                            , {field: 'supplier', title: '供应商'}
                            , {field: 'supplierName', title: '供应商联系人'}
                            , {field: 'department', title: '采购部门'}
                            , {field: 'creatorName', title: '采购申请人'}
                            , {field: 'orderAuditor', title: '订单审核人'}
                        ]]
                    });

                    let purchaseSignDetailsTbList = table.render({
                        elem: '#purchaseSignDetailsTableList',
                        data: purchaseSignDetailsTableData[0].detailList,
                        page: true,
                        height: 450,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'skuPic', title: '物料图片', templet: d => '<img src="' + d.skuPic + '">'}
                            ,  {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuSpec', title: '规格号'}
                            , {field: 'productTypeName', title: '物料类型'}
                            , {field: 'marketPrice', title: '物料单价'}
                            , {field: 'unitName', title: '计价单位'}
                            , {field: 'num', title: '采购数量'}
                            , {field: 'num', title: '签收数量'}
                            , {field: 'amount', title: '小计金额'}
                            , {field: '', title: '包装单位'}
                            , {field: 'packName', title: '包装方式'}
                            , {field: 'packNum', title: '包装数量'}
                        ]]
                    });
                }
            });
        }

        // 打印条码弹窗
        function showPlantLable(data) {
            admin.open({
                type: 1,
                area: ['1400px', '800px'],
                offset: '65px',
                title: '打印条码',
                content: $('#purchaseSignDetails').html(),
                success: function () {
                    let plantLableDetailsTb = table.render({
                        elem: '#purchaseSignDetailsTable',
                        url: config.base + 'enterprisecab/order/admin/purchaseSign/getLableBySignId?id=' + data.id,
                        page: true,
                        height: 590,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'number', title: '序号', width: 60, type: 'numbers'}
                            , {field: 'packLabeCode', title: '包装编码'}
                            , {field: 'purchaseCode', title: '所属入库计划'}
                            , {field: 'productName', title: '物料系列名称'}
                            , {field: 'skuSpec', title: '物料包装规格'}
                            , {field: 'packName', title: '包装规格'}
                            , {field: 'baseRate', title: '单位包装数'}
                            , {field: 'unitName', title: '最小单位'}
                            , {field: '', title: '打印次数'}
                            , {align: 'left', toolbar: '#purchaseSignLableTableBar', title: '操作'}
                        ]]
                    });

                    // 工具条点击事件
                    table.on('tool(purchaseSignDetailsTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'printBarcode') { //打印条码
                            getPrintBarcode(data)
                        }
                    });
                }
            });
        }

        // 请求条码接口
        function getPrintBarcode(data) {
            layer.load(2);
            admin.req('enterprisecab/order/admin/purchaseSign/getBarCode', {code: data.packLabeCode}, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    let newstr = `
                        <div style="padding: 20px;width: 100%;box-sizing: border-box;">
                            <div style="height: 150px;width: 100%">
                                <div style="width: 150px;float: left;height: 100%;">
                                    <img src="${res.data}" style="max-width: 100%; width: 100%;height: 100%;"/>
                                </div>
                                <div style="width: calc(100% - 150px); float: left;height: 100%; box-sizing: border-box; padding: 15px; font-size: 16px">
                                    ${data.productName}
                                </div>
                            </div>
                            <p style="margin-top: 5px;font-size: 16px;width: 100%;box-sizing: border-box;height: 20px; overflow: hidden"> ${data.packLabeCode}</p>
                        </div>
                    `;
                    printBarcode(newstr)
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'GET');
        }

        // 打印条码
        function printBarcode(data) {
            let printBarcodePopup = admin.open({
                type: 1,
                area: ['330px', '350px'],
                offset: '65px',
                title: "打印预览",
                content: data,
                btn: ['打印', '取消'],
                yes: function () {
                    let newWin = window.open("");//新打开一个空窗口
                    newWin.document.write(data);//将表格添加进新的窗口
                    newWin.document.close();//在IE浏览器中使用必须添加这一句
                    newWin.focus();//在IE浏览器中使用必须添加这一句
                    newWin.print();//打印
                    newWin.close();//关闭窗口
                },
                btn2: function () {
                    layer.close(printBarcodePopup);
                }

            })

        }


        let addSigningProductData = '', supplyOrderValue = '', signingProductData = [];

        // 显示添加采购签收弹窗
        function showAddPurchaseOrder(data) {
            admin.open({
                type: 1,
                area: ['82%', '800px'],
                offset: '65px',
                title: '添加生产入库计划',
                content: $('#addOrderSigningInfo').html(),
                success: function () {
                    addSigningProductData = '';
                    supplyOrderValue = '';
                    signingProductData = [];


                    //供货订单
                    admin.req('enterprisecab/order/admin/purchase/getPurchaseList', {}, res => {
                        if (res.code === 200) {
                            loadSelectHtml(res.data, '请选择供货订单', 'skuCode', 1)
                        }
                    }, 'GET');
                    form.on('select(skuCode)', d => {
                        supplyOrderValue = d.value;
                        admin.req('enterprisecab/order/admin/purchaseSign/getPurchaseByCode', {code: supplyOrderValue}, res => {
                            if (res.code === 200) {
                                form.val('addOrderSigningInfoForm', res.data);
                                addSigningProductData = res.data;
                            } else {
                                form.val('addOrderSigningInfoForm', {});
                                addSigningProductData = '';
                            }
                            signingProductData = [];
                            table.reload('addPurchaseOrderTable', {data: signingProductData});
                        }, 'GET');
                    });

                    form.render("select");
                    let addPurchaseOrderTb = table.render({
                        elem: '#addPurchaseOrderTable',
                        data: signingProductData,
                        page: true,
                        cellMinWidth: 100,
                        height: 450,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'skuPic', title: '物料图片', templet: d => '<img src="' + d.skuPic + '"/>'}
                            ,  {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuSpecValueNames', title: '规格号'}
                            , {field: 'productType', title: '物料类型'}
                            , {field: 'marketPrice', title: '物料单价'}
                            , {field: 'unitName', title: '计价单位'}
                            , {field: 'num', title: '采购数量'}
                            , {field: '', title: '签收数量'}
                            , {field: 'amount', title: '小计金额'}
                            , {field: '', title: '包装单位'}
                            , {
                                field: 'packName',
                                title: '包装方式',
                                templet: "#addOrderSigningInfoSelectBar",
                                width: 200
                            }
                            , {
                                field: 'packNum',
                                title: '包装数量',
                                templet: d => '<input name="packNum" class="layui-input" disabled/>'
                            }

                        ]],
                        done: function (res, curr, count, q) {
                            //请选择包装方式
                            admin.req('enterprisecab/order/admin/purchaseSign/getPackAll', {}, res => {
                                if (res.code === 200) {
                                    loadSelectHtml(res.data, '请选择包装方式', 'packName', 4);
                                }
                            }, 'GET');
                        }
                    });

                    form.on('select(packName)', data => {
                        let packNum = Math.ceil($(data.elem).parents('tr').find('td[data-field="num"]').text() / $(data.elem[data.elem.selectedIndex]).attr('baseRate'));
                        $(data.elem).parents('tr').find('input[name="packNum"]').val(packNum);
                        signingProductData[$(data.elem).parents('tr').index()].packNum = packNum;
                        signingProductData[$(data.elem).parents('tr').index()].packName = data.elem[data.elem.selectedIndex].text;

                        signingProductData[$(data.elem).parents('tr').index()].baseRate = $(data.elem[data.elem.selectedIndex]).attr('baseRate');
                        signingProductData[$(data.elem).parents('tr').index()].packId = data.value
                    });

                    $('#addSigningProductBtn').click(function () {
                        if (supplyOrderValue) {
                            showAddSigningProduct(addSigningProductData)
                        } else {
                            $('[name="supplyOrder"]').addClass('layui-form-danger');
                            layer.msg('请选择供货订单', {icon: 5})
                        }
                    });
                    form.on('submit(addOrderSigningInfoSubmit)', d => {
                        if (signingProductData.length <= 0) {
                            layer.msg('请添加需要签收的物料', {icon: 5});
                            return false;
                        }
                        let orderMoneyValue = 0;
                        signingProductData.forEach(item => {
                            orderMoneyValue += item.amount
                        });

                        d.orderMoney = orderMoneyValue;
                        d.field = Object.assign(d.field, addSigningProductData);
                        d.field.purchaseDetailList = signingProductData;
                        layer.load(2);
                        admin.req('enterprisecab/order/admin/purchaseSign/purchaseSign', JSON.stringify(d.field), res => {
                            layer.closeAll('loading');
                            if (res.code === 200) {
                                layer.closeAll();
                                layer.msg(res.msg, {icon: 1});
                                table.reload('purchaseSignTable');

                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8')
                    })
                }
            });
        }


        //显示添加采购商品弹窗
        function showAddSigningProduct(_data) {
            let addSigningProductPopUp = admin.open({
                type: 1,
                area: ['75%', '700px'],
                offset: '85px',
                title: '添加签收物料信息',
                content: $('#addSigningProduct').html(),
                success: function () {
                    let addSigningProductTb = table.render({
                        elem: '#addSigningProductTable',
                        data: [_data],
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'purchaseTypeName', sort: true, title: '采购类型'}
                            , {field: 'purchaseDegreeName', sort: true, title: '紧急程度'}
                            , {field: 'supplier', sort: true, title: '供应商'}
                            , {field: 'supplierName', sort: true, title: '供应商联系人'}
                            , {
                                field: 'department',
                                sort: true,
                                title: '采购部门',
                                templet: d => d.department == 1 ? '采购部' : d.department
                            }
                            , {field: 'creatorName', sort: true, title: '采购申请人'}
                            , {field: 'orderAuditor', sort: true, title: '订单审核人'}
                        ]],
                    });

                    let addSigningProductTbList = table.render({
                        elem: '#addSigningProductTableList',
                        data: _data.purchaseDetailList.filter((item) => !signingProductData.some((ele) => ele.id === item.id)),
                        page: true,
                        cellMinWidth: 100,
                        height: 400,
                        cols: [[
                            {type: 'checkbox'}
                            , {
                                field: 'skuPic',
                                sort: true,
                                title: '物料图片',
                                templet: d => '<img src="' + d.skuPic + '"/>'
                            }
                            , {field: 'skuCode', sort: true, title: '物料编号'}
                            , {field: 'skuSpec', sort: true, title: '规格号'}
                            , {field: 'productType', sort: true, title: '物料类型'}
                            , {field: 'marketPrice', sort: true, title: '物料单价'}
                            , {field: 'unitName', sort: true, title: '计价单位'}
                            , {field: 'num', sort: true, title: '采购数量'}
                            , {field: 'amount', sort: true, title: '小计金额'}
                            // , {align: 'left', toolbar: '#addPurchaseCommodityBar', title: '操作'}
                        ]],
                        parseData: (res) => {
                            // res.data = res.data.filter((item) => !showAddPurchaseOrderData.some((ele) => ele.id === item.id));
                            // return res;
                        }
                    });

                    $('#addSigningProductSubmit').click(() => {
                        let checkStatus = table.checkStatus('addSigningProductTableList');
                        if (checkStatus.data.length > 0) {

                            let showAddPurchaseOrderDataArrays = [...signingProductData, ...checkStatus.data];

                            let showAddPurchaseOrderDataArraysMap = new Map();
                            for (let item of showAddPurchaseOrderDataArrays) {
                                if (!showAddPurchaseOrderDataArraysMap.has(item.id)) {
                                    showAddPurchaseOrderDataArraysMap.set(item.id, item)
                                }
                            }
                            signingProductData = [...showAddPurchaseOrderDataArraysMap.values()];
                            layer.close(addSigningProductPopUp);
                            table.reload('addPurchaseOrderTable', {data: signingProductData});

                        } else {
                            layer.msg('请选择要采购的商品', {icon: 5})
                        }

                    })
                }
            });
        }


        /*渲染下拉框*/
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type === 1) {
                    html += `<option value='${data[i].code}'>${data[i].code}</option>`;
                } else if (type === 2) {
                    html += `<option value='${data[i].id}' administratorName='${data[i].administratorName}'>${data[i].companyName}</option>`;
                } else if (type === 3) {
                    html += `<option value='${data[i].id}'>${data[i].username}</option>`;
                } else if (type === 4) {
                    html += `<option baseRate='${data[i].baseRate}' value='${data[i].id}'>${data[i].name}</option>`;
                }

            }

            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }
    });
</script>